package tset1;

import java.util.Random;

public class Man {
    private static int sum;
    public static void main(String[] args) throws InterruptedException {
        Object locker=new Object();
        int arrays[]=new int[10000];
        for (int i = 0; i <arrays.length ; i++) {
            arrays[i]=new Random(1).nextInt(100)+1;
        }
        Thread t1=new Thread(()->{
            synchronized (locker){
                for (int i = 0; i < arrays.length; i++) {
                    if(i%2==0){
                        sum+= arrays[i];
                    }
                }
            }
        },"T1");
        Thread t2=new Thread(()->{
            synchronized (locker){
                for (int i = 0; i < arrays.length; i++) {
                    if(i%2!=0){
                        sum+= arrays[i];
                    }
                }
            }
        },"T2");
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("sum=" + sum);
    }
}
